// holds an instance of XMLHttpRequest 
var xmlHttp = createXmlHttpRequestObject(); 
 
// creates an XMLHttpRequest instance 
function createXmlHttpRequestObject()  
{ 
  // will store the reference to the XMLHttpRequest object 
  var xmlHttp; 
  // this should work for all browsers except IE6 and older 
  try 
  { 
    // try to create XMLHttpRequest object 
    xmlHttp = new XMLHttpRequest(); 
  } 
  catch(e) 
  { 
    // assume IE6 or older 
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", 
                                    "MSXML2.XMLHTTP.5.0", 
                                    "MSXML2.XMLHTTP.4.0", 
                                    "MSXML2.XMLHTTP.3.0", 
                                    "MSXML2.XMLHTTP", 
                                    "Microsoft.XMLHTTP"); 
    // try every prog id until one works 
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)  
    { 
      try  
      {  
        // try to create XMLHttpRequest object 
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]); 
      }  
      catch (e) {} 
    } 
  } 
  // return the created object or display an error message 
  if (!xmlHttp) 
    alert("Error creating the XMLHttpRequest object."); 
  else  
    return xmlHttp; 
}

 // HAM XU LY CHINH
	function checkpass()
	{		
		var pass = document.getElementById("idpassword").value;  	
		var repass = document.getElementById("idrepassword").value; 
		if(pass != repass)
		{
			alert('Máº­t kháº©u khÃ´ng trÃ¹ng!');
			return false;
		}		
	}

 function ajlikes(like_tables, like_tables_id, like_user, like_id, songuoilike)
 {
	if(like_id != '')
	{	
		// var address="hoidap/Source/likes/index/delete?like_tables="+like_tables+"&like_tables_id="+like_tables_id+"&like_user="+like_user+"&like_id="+like_id;
		 var address="http://localhost/hoidap/Source/likes/index/delete?like_tables="+like_tables+"&like_tables_id="+like_tables_id+"&like_user="+like_user+"&like_id="+like_id+"&songuoilike="+songuoilike;
	}
	else
	{	
		// var address="hoidap/Source/likes/index/add?like_tables="+like_tables+"&like_tables_id="+like_tables_id+"&like_user="+like_user+"&like_id="+like_id;
		var address="http://localhost/hoidap/Source/likes/index/add?like_tables="+like_tables+"&like_tables_id="+like_tables_id+"&like_user="+like_user+"&like_id="+like_id+"&songuoilike="+songuoilike;
	}
 	if(xmlHttp)
	{
		try
		{
			xmlHttp.onreadystatechange = function() {
				if (xmlHttp.readyState == 4)  { 
				    if (xmlHttp.status == 200) {
						try {
							var response = xmlHttp.responseText;						
							document.getElementById("like_"+like_tables+"_"+like_tables_id).innerHTML = response;  
							test(like_tables, like_id, like_tables_id, songuoilike);											
						}
						catch(e){
							alert("Error reading the response: " + e.toString());
						}
					}
				}
			}			
			xmlHttp.open("GET",address , true);
			xmlHttp.send(null);		
		}
		catch(e)
		{
			alert("KhÃ´ng thá»ƒ try cÃ¢p server: " + e.toString()); 
		}
	}	
 }
 

  function test(like_tables, like_id, like_tables_id, songuoilike)
 {
	if(songuoilike != '0')
	{
		document.getElementById("thichdieunay"+like_tables+like_tables_id).innerHTML = "ThÃ­ch Ä‘iá»�u nÃ y"; 
	}
	else
	{
		if(like_id != '')
		{	
			document.getElementById("thichdieunay"+like_tables+like_tables_id).innerHTML = ""; 
		}	
		else
		{
			document.getElementById("thichdieunay"+like_tables+like_tables_id).innerHTML = "ThÃ­ch Ä‘iá»�u nÃ y"; 
		}
		
	}

	
	if(like_id != '')
	{
		document.getElementById("youlike"+like_tables+like_tables_id).innerHTML = "";
		document.getElementById("youlikeand"+like_tables+like_tables_id).innerHTML = ""; 	
	}
	else
	{
		document.getElementById("youlike"+like_tables+like_tables_id).innerHTML = "Báº¡n"; 
		if(songuoilike != 0)
		{
			document.getElementById("youlikeand"+like_tables+like_tables_id).innerHTML = " vÃ  ";  			
		}
		else
		{
			document.getElementById("youlikeand"+like_tables+like_tables_id).innerHTML = ""; 	
		}
	}

 }
 
 

